package com.maoye.ossp.biz.brand.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hotent.base.api.query.QueryFilter;
import com.hotent.base.api.query.QueryOP;
import com.hotent.base.core.util.string.StringUtil;
import com.maoye.ossp.biz.brand.entity.BrandPosition;
import com.maoye.ossp.biz.brand.entity.BrandPositionLog;
import com.maoye.ossp.biz.brand.service.BrandPositionService;
import com.maoye.ossp.common.entity.Page;
import com.maoye.ossp.common.web.BaseController;
import com.maoye.ossp.sys.base.entity.SysBaseFloorAttment;
import com.maoye.ossp.sys.base.service.SysBaseFloorAttmentService;
import com.maoye.ossp.sys.org.util.UserUtils;
import com.maoye.sc.api.domain.User;

/**
 * 品牌落位查询
* @ClassName: BrandPositionController
* @Description: 
* @Company: MOI
* @author linzhizhong
* @date 2014年6月3日 下午10:27:29
*
 */
@Controller
@RequestMapping("biz/brand/brandPosition/")
public class BrandPositionController extends BaseController {

	@Resource
	BrandPositionService brandPositionService;
	@Resource
	SysBaseFloorAttmentService sysBaseFloorAttmentService;    //楼层附件
	/**
	 * 品牌落位查询
	 * @param brandLevel
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "list")
	public String list(BrandPosition brandPosition, HttpServletRequest request, HttpServletResponse response, Model model) {
		QueryFilter queryFilter = getQuerFilter(request, brandPosition);
		if(StringUtil.isNotEmpty(brandPosition.getFloorId())){
			queryFilter.addFilter("floor", brandPosition.getFloorId(), QueryOP.EQUAL);
		}
		if(StringUtil.isNotEmpty(brandPosition.getStoreId())){
			queryFilter.addFilter("siteid", brandPosition.getStoreId(), QueryOP.EQUAL);
		}
		if(StringUtil.isNotEmpty(brandPosition.getBrand())){
			queryFilter.addFilter("title", brandPosition.getBrand(), QueryOP.LIKE);
		}	
		if(StringUtil.isNotEmpty(brandPosition.getMerchant_id())){
			queryFilter.addFilter("merchant_id", brandPosition.getMerchant_id(), QueryOP.LIKE);
		}	
		if(StringUtil.isNotEmpty(brandPosition.getBrandCode())){
			queryFilter.addFilter("brandCode", brandPosition.getBrandCode(), QueryOP.LIKE);
		}	
		
		
		queryFilter.addFilter("floorNo", brandPosition.getFloorId(), QueryOP.EQUAL);
		Page<SysBaseFloorAttment> page2 = (Page<SysBaseFloorAttment>)sysBaseFloorAttmentService.find(queryFilter);
		List<SysBaseFloorAttment> attList=page2.getList();
		
		if(attList!=null&&!attList.isEmpty()){
			model.addAttribute("floorAttId", attList.get(0).getId().toString());
		}
		
		model.addAttribute("brandPosition", brandPosition);
		Page<BrandPosition> page = brandPositionService.find(queryFilter);
		model.addAttribute("page", page);
		return resultPage("/biz/brand/resetBrand/list", model, request);
	}
	
	
	@RequestMapping(value = "{id}/brandView")
	public String brandView(@PathVariable String id, Model model,HttpServletRequest request) {
		BrandPosition brandPosition = brandPositionService.get(Long.valueOf(id));
		model.addAttribute("brandPosition", brandPosition);
		QueryFilter queryFilter = getQuerFilter(request,brandPosition);
		queryFilter.addFilter("floorNo", brandPosition.getFloor(), QueryOP.EQUAL);
		Page<SysBaseFloorAttment> page = (Page<SysBaseFloorAttment>)sysBaseFloorAttmentService.find(queryFilter);
		List<SysBaseFloorAttment> attList=page.getList();
		if(attList!=null&&!attList.isEmpty()){
			model.addAttribute("floorAttId", attList.get(0).getId().toString());
		}
		return "/biz/brand/resetBrand/brandView";
	}
	
}
